<template>
	<!-- 瀑布流 -->
	<van-list
		  v-model:loading="loading"
		  :finished="finished"
		  finished-text="没有更多了"
		  :immediate-check="false"
		  offset="100"
		  @load="onLoad"
	>
	<card :userTravels="userTravels"/>
	</van-list>
	<div style="height: 100px;"></div>
</template>

<script setup>
	import card from '@/page/Common-components/card-flow.vue'
	import request from '@/api/request.js'
	import { ref,onMounted,onUnmounted } from 'vue'
	import { useRoute  } from 'vue-router'
	const $routeQuery = useRoute()  // 用于接收路由参数的
	const fetchValue = ref('')//存储上个页面的值
	const userTravels = ref([])//接收游记数据
	onMounted(async()=>{
		// console.log($routeQuery.query);
		fetchValue.value = $routeQuery.query
		switch (fetchValue.value.type){
			case '101':
			// console.log('101')
			// 首页分类游记
			const classifyT = await request.get('/classify_travels',{keywords:fetchValue.value.keywords,page:1})
			// console.log(classifyT)
			userTravels.value = classifyT.data
			break;
			case '102':
			// 发现页分类游记
			const addressQT = await request.get('/address_query_travels',{address:fetchValue.value.address,keywords:fetchValue.value.keywords,page:1})
			// console.log(addressQT)
			userTravels.value = addressQT.data
			// console.log('102')
			break;
			case '103':
			// 我的收藏
			const myCollection = await request.get('/my_collection',{page:1})
			userTravels.value = myCollection.data
			// console.log('103')
			break;
		}
	})
	const loading = ref(false);
	const finished = ref(false);
	// 上啦加载
	const page = ref(1)
	async function onLoad(){
		page.value++
		if(fetchValue.value.type == '101'){
			var user_travels = await request.get('/classify_travels',
				{keywords:fetchValue.value.keywords,
				page:page.value,
				},
			)
		}else if(fetchValue.value.type == '102'){
			var user_travels = await request.get('/address_query_travels',
				{address:fetchValue.value.address,
				keywords:fetchValue.value.keywords,
				page:page.value,
				},
			)
		}else if(fetchValue.value.type == '103'){
			var user_travels = await request.get('/my_collection',{page:page.value})
		}
		userTravels.value = [...userTravels.value,...user_travels.data]
		loading.value = false
		if(user_travels.data.length === 0){
			finished.value = true
		}
	}
	onUnmounted(()=>{
		finished.value = false
	})
</script>

<style>
</style>